<template>

  <div style="padding:20px;" id="app">
    <div class="panel panel-primary">

      <table class="table table-bordered table-striped text-center">
        <thead>
        <tr>
          <th>ID</th>
          <th>姓名</th>
          <th>地址</th>
          <th>工作</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(user,index) in users">
          <td>{{ index + 1 }}</td>
          <td>{{ user.name }}</td>
          <td>{{ user.address }}</td>
          <td>{{ user.job }}</td>
          <td>
            <button style="background: #FF5722;color: white;border: none"   v-on:click="remove(index)">删除</button>
          </td>
        </tr>
        <tr>
          <td></td>
          <td><input type="text" id="name" v-model="user.name"/></td>
          <td><input type="text" id="address" v-model="user.address"/></td>
          <td><input type="text" id="job" v-model="user.job"/></td>
          <td>
            <button style="background: #42b983;color: white;border: none" @click="insert">增加</button>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
  </div>


</template>

<script>
  export default {
    name: 'hello',
    data () {
      return {
        user: {'name': '', 'address': '', 'job': ''},
        users: [
          {'name': '李四', 'address': '贵州', 'job': 'java初级开发工程师'},
          {'name': '张三', 'address': '福州', 'job': '前端开发工程师'},
          {'name': '王二', 'address': '上海', 'job':'运维工程师'},
          {'name': '赵四', 'address': '北京', 'job':'运维工程师'},
          {'name': '小明', 'address': '重庆', 'job':'产品经理'},
        ]
      }
    },
    methods: {
      insert: function () {
        this.users.push(this.user)
      },
      remove: function (index) {
        this.users.splice(index, 1)
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  h1, h2 {
    font-weight: normal;
  }

  ul {
    list-style-type: none;
    padding: 0;
  }

  li {
    display: inline-block;
    margin: 0 10px;
  }

  a {
    color: #42b983;
  }
  tr,th{
    text-align:center;
  }
</style>

